package com.fz.controller;

import com.fz.common.ResponseEntity;
import com.fz.entity.system.Dictionary;
import com.fz.entity.system.DictionaryValue;
import com.fz.service.CommonService;
import com.fz.vo.system.area.AreaVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(value = "公用接口", tags = "公用接口")
@RequestMapping("/common")
@CrossOrigin
@SuppressWarnings("unchecked")
public class CommonController {

    @Resource
    private CommonService commonService;

    /**
     * @方法描述: 根据字典key查询字典名称
     * @参数:
     * @返回值:
     * @创建人: I am God
     * @创建时间:: 2021/3/9
     */
    @GetMapping("/findDict")
    @ApiOperation(value = "根据字典key查询字典名称")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictKey", value = "字典key", required = true, dataType = "string", paramType = "query")
    })
    public ResponseEntity<Dictionary> findDict(String dictKey) throws Exception {
        return commonService.findDict(dictKey);
    }

    /**
     * @方法描述: 根据字典id查询对应的字典值
     * @参数:
     * @返回值:
     * @创建人: I am God
     * @创建时间:: 2021/3/9
     */
    @GetMapping("/findDictValue")
    @ApiOperation(value = "根据字典id查询对应的字典值")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictid", value = "字典id", required = true, dataType = "string", paramType = "query")
    })
    public ResponseEntity<List<DictionaryValue>> findDictValue(String dictid) throws Exception {
        return commonService.findDictValue(dictid);
    }

    @GetMapping("/findComAreaList")
    @ApiOperation(value = "根据行政区划查询查询对应的字典值")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "行政编码", required = false, dataType = "string", paramType = "query")
    })
    public ResponseEntity<AreaVo> findComAreaList(@RequestParam(defaultValue = "0001") String code) {
        return commonService.findAreaList(code);
    }
}
